<!--
 * @name: 
 * @version: 1.1.1
 * @Author: 刘大可
 * @Date: 2022-05-06 12:37:22
 * @LastEditors: 刘大可
 * @LastEditTime: 2022-11-05 10:06:00
-->
<template>
	<view>
		<cu-custom bgColor="bgmain" id="vont">
            <view slot="content">选择学校</view>
        </cu-custom>
        <!-- <picker
            mode="region"
            v-model="city"
            @change="changeCity"
        >
                选地址
        </picker> -->
        <!-- <view class="changeCity" @click="changeCity">
            选地址
        </view> -->
        <view class="row padding" style="width:100%;">
            <pick  @getRegion="handleGetRegion">
                <view class="city row">
                    <!-- <image
                        class="address margin-right-sm"
                        src="/static/address.png"
                        mode="scaleToFill"
                    /> -->
                    <view class="font">{{formData.city||'选择城市'}}</view>
                    <view class="cuIcon-triangledownfill"></view>

                </view>
            </pick>
            <view class="search row padding-lr">
                <image
                    class="icon margin-right-sm"
                    src="/static/search2.png"
                    mode="scaleToFill"
                />
                <input type="" v-model="kwd" placeholder="请输入学校名称" />
                
            </view>
        </view>
        <view class="schools margin">
            <block v-for="(item,index) in schoolList" :key="index">
                <view class="school margin-bottom" :class="index==flg?'cur':''" @click="changeSchool(index)">
                    <image
                        class="logo"
                        :src="item.logo"
                        mode="scaleToFill"
                    />
                    <view class="ciy margin-top-xs">{{item.city}}</view>
                    <view class="name">{{item.s_name}}</view>
                </view>
            </block>
            <view class="kong"></view>
            <view class="kong"></view>
            <view class="kong"></view>
            <view class="kong"></view>
        </view>

        <view class="notData" v-if="schoolList.length==0">暂无学校</view>
        <!-- <view class="enter" @click="enter" v-if="schoolList.length>0">确定</view> -->
	  </view>
</template>

<script>
    import  pick from '@/components/pick-regions/pick-regions.vue'
	var app = getApp();

	export default {
        components: {
            pick
        },
		data() {
			return {
				...this.configInfo,
                formData:{
                    kwd:"",
                    city:""
                },
                kwd:"",
                schoolList:[],
                flg:-1

				

				
			};
		},
        watch: {
            kwd(val){
                this.formData.kwd=val
                this.initData()
            }
        },
		async onLoad(options) {
			// this.login().then((res)=>{
			//     console.log("您已登陆！");
			// })
			
                this.initData()
		
				
			

		},
		onReady: function() {
			// 页面渲染完成
		},
		onShareAppMessage: function() {
			// return {
			//   title: '自定义标题',
			//   path: '/page/user?id=123',
			// }
		},
		onShareTimeline: function() {},
		onShow: function() {
			
		},
		onHide: function() {
			// 页面隐藏
		},
		onUnload: function() {
			// 页面关闭
            uni.$emit('changeSchools', {})
		},
		onReachBottom: function() {
			// this.getOrderData()
		},
		methods:{
			async closeAuth(){
				await this.tips.tips("如果想重新授权，请前往设置！")
				this.isHomeAuth=true
				uni.setStorageSync('isHomeAuth', true)
			},
            async initData(){
                   let res=await  this.request('School/index',{
                    openid: uni.getStorageSync('openid') ? uni.getStorageSync('openid') :
                    'nologinuser' ,
                    ...this.formData,
                    // lon: wx.getStorageSync('city').location.lng,
                    // lat: wx.getStorageSync('city').location.lat,
                })
                this.schoolList=res.data.data.list
                uni.setStorageSync('schoolList', res.data.data.list);
                // uni.setStorageSync('sys', res.data.data.sys);

                this.flg=-1
            },
            handleGetRegion(e){
                this.formData.city=e[1].name
                this.initData()
				// this.address = e[0].name + e[1].name+e[2].name
			},
            changeCity(e){
                console.log(e);
                uni.chooseLocation({
                    success:(res)=>{
                        console.log(res);
                    }
                })
            },
            changeSchool(i){
                this.flg=i

                this.enter()

            },
            enter(){
                if (this.flg==-1) {
                    this.tups.tips("请选择学校")
                    return false
                }
                uni.setStorageSync('schoolId',this.schoolList[this.flg].s_id)
                uni.reLaunch({ url: '/gc_school/pages/home/index' })

                // uni.navigateBack({ delta: 1 })
            }
			
		}
	};
</script>

<style lang="scss">
	@import "./main.scss";
</style>